package com.example.zhongshuishi.service.implService;

import com.example.zhongshuishi.entity.StudentDto;
import com.example.zhongshuishi.mapper.StudentMapper;
import com.example.zhongshuishi.service.StudentService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public int addStudent(StudentDto studentDto) {
        return studentMapper.insert(studentDto);
    }

    @Override
    public int deleteStudent(String id) {
        return studentMapper.deleteById(id);
    }

    @Override
    public int updateStudent(StudentDto studentDto) {
        return studentMapper.update(studentDto);
    }

    @Override
    public int updateById(StudentDto studentDto) {
        return studentMapper.updateById(studentDto);
    }

    @Override
    public StudentDto getStudentById(String id) {
        return studentMapper.selectById(id);
    }

    @Override
    public StudentDto getStudentByPhone(String phone) {
        return studentMapper.selectByPhone(phone);
    }

    @Override
    public List<StudentDto> getAllStudents() {
        return studentMapper.selectAll();
    }

    @Override
    public int updatePaymentStatus(String id, String paymentStatus) {
        return studentMapper.updatePaymentStatus(id, paymentStatus);
    }

    @Override
    public List<StudentDto> selectByPersonnal(Integer teacherId,String teacher, Integer wxId, String stuName, String stuIdnumber, String stuPhone,Integer currPage,Integer pageSize) {
        if(currPage != null||pageSize != null){
            PageHelper.startPage(currPage,pageSize);
        }
        List<StudentDto> studentDtos = studentMapper.selectByPersonnal(teacherId,teacher, wxId, stuName, stuIdnumber, stuPhone);
        return studentDtos;
    }

    @Override
    public int addOrder(StudentDto studentDto) {
        return studentMapper.insertOrder(studentDto);
    }

    @Override
    public int addTraining(StudentDto studentDto) {
        return  studentMapper.insertTraining(studentDto);
    }

    @Override
    public void updateTraining(StudentDto student) {
        studentMapper.updateTraining(student);
    }

    @Override
    public String selectPaymentStatus(String id) {
       return studentMapper.selectPaymentStatus(id);

    }


    @Override
    public boolean isTeacherExist(String teacherName) {
        String teacherId = studentMapper.isTeacherExist(teacherName);
        if (teacherId != null && !teacherId.isEmpty()) {
            return true;
        }
        return false;
    }
}